<template>
  <RadioGroup v-model="currentNs" vertical @on-change="chooseNs">
    <Radio :label="allNs" v-if="!disall&&(!showmode||allNs===currentNs)" :disabled="showmode"></Radio>
    <Radio v-for="(ns,i) in namespace.list" :key="i" :label="ns.namespace" v-if="!showmode||ns.namespace===currentNs" :disabled="showmode"></Radio>
  </RadioGroup>
</template>
<script>
  export default {
    props: {
      current: String,
      showmode: Boolean,
      disall: Boolean,
    },
    data() {
      return {
        currentNs: '',
        allNs: '',
        namespace: {
          list: [],
        }
      }
    },
    mounted() {
      this.allNs = this.$t('page.base.nsall')
      this.currentNs = this.current ? this.current : this.allNs
      this.loadNs()
    },
    methods: {
      loadNs() {
        this.$storage.listNamespace(namespaces => {
          this.namespace.list = namespaces
        })
      },
      chooseNs(ns) {
        this.$emit('onChosen', (ns === this.allNs) ? '' : ns)
      }
    }
  }
</script>